﻿package view.loader
{
    import __AS3__.vec.*;
    import com.core.*;
    import flash.events.*;
    import morn.core.handlers.*;
    import pluginfw.*;

    public class UIAssetsLoader extends EventDispatcher
    {
        private var mLoadList:Vector.<String>;
        private var mCurIndex:int = 0;

        public function UIAssetsLoader()
        {
            this.mLoadList = new Vector.<String>;
            return;
        }// end function

        public function appendToList(param1:String) : void
        {
            if (param1 == null || StringUtil.trim(param1).length == 0)
            {
                return;
            }
            if (this.mLoadList.indexOf(param1) == -1)
            {
                this.mLoadList.push(param1);
            }
            return;
        }// end function

        public function beginLoad() : void
        {
            this.mCurIndex = 0;
            if (this.mCurIndex < this.loadCount)
            {
                this.nextLoad();
            }
            else
            {
                if (hasEventListener(Event.COMPLETE))
                {
                    dispatchEvent(new Event(Event.COMPLETE));
                }
                ModelProxy.change("progress", "complete", 4);
            }
            return;
        }// end function

        private function nextLoad() : void
        {
            var _loc_1:* = "加载中 " + this.loadIndex + "/" + this.loadCount + "...";
            ModelProxy.change("progress", "progress", {name:_loc_1, type:4, cur:0, max:100});
            App.mloader3.loadMSWF(this.mLoadList[this.mCurIndex], 1, new Handler(this.loadComplete), null, new Handler(this.loadError));
            return;
        }// end function

        private function loadComplete(param1:Object) : void
        {
            var _loc_2:String = this;
            var _loc_3:* = this.mCurIndex + 1;
            _loc_2.mCurIndex = _loc_3;
            if (this.mCurIndex < this.loadCount)
            {
                this.nextLoad();
            }
            else
            {
                ModelProxy.change("progress", "complete", 4);
                if (hasEventListener(Event.COMPLETE))
                {
                    dispatchEvent(new Event(Event.COMPLETE));
                }
            }
            return;
        }// end function

        public function dispose() : void
        {
            if (this.mLoadList)
            {
                this.mLoadList = null;
            }
            return;
        }// end function

        private function loadError(param1:Object) : void
        {
            return;
        }// end function

        private function loadProgress(param1:Number) : void
        {
            return;
        }// end function

        public function get loadIndex() : int
        {
            return this.mCurIndex;
        }// end function

        public function get loadCount() : int
        {
            if (this.mLoadList)
            {
                return this.mLoadList.length;
            }
            return 0;
        }// end function

    }
}
